package com.zhuxulin.tab.utils;

import java.io.File;
import java.io.FileFilter;
import java.io.FilenameFilter;

public final class FileUtils {
	private static String TAG=FileUtils.class.getSimpleName();
	public static File[] listFiles(String dir) {
		return listFiles(dir, null);
		// return (dir != null && !dir.equals("")) ? new File(dir).listFiles()
		// : null;
	}

	public static File[] listFiles(FileFilter filter, File dir) {
		return (!dir.isDirectory()) ? null : dir.listFiles(filter);
		// dir.listFiles();
	}

	public static File[] listFiles(File dir, FilenameFilter filter) {
		return (!dir.isDirectory()) ? null : dir.listFiles(filter);
	}

	public static File[] listFiles(String dir, FileFilter filter) {
		return (dir != null && !dir.equals("")) ? (filter != null) ? new File(
				dir).listFiles(filter) : new File(dir).listFiles() : null;
	}

	public static String[] listFileNames(String dir, FileFilter filter) {
		File[] files = listFiles(dir, filter);
		if (files == null || files.length <= 0) {
			return null;
		}
		String[] names = new String[files.length];
		for (int i = 0; i < files.length; i++) {
			names[i] = files[i].getName();
		}
		return names;
	}
}
